import Vue from "vue";
import VueRouter from "vue-router";
import login from '@/views/login'
import Loyout from '@/views/Loyout'
// 子组件
import home from '@/views/home.vue'
import member from '@/views/member.vue'
import supplier from '@/views/supplier.vue'
import goods from '@/views/goods.vue'
import staff from '@/views/staff.vue'

Vue.use(VueRouter);

//解决报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
  path: '/login',
  component: login,
  name: 'login'
},{
  path: '/',
  component: Loyout,
  name: 'Loyout',
  redirect: '/home',
  children: [{
    path: '/home',
    name: 'home',
    component: home,
    meta: {title: '首页'}
  },{
    path: '/member',
    name: 'member',
    component: member,
    meta: {title: '会员管理'}
  },{
    path: '/supplier',
    name: 'supplier',
    component: supplier,
    meta: {title: '供应商管理'}
  },{
    path: '/goods',
    name: 'goods',
    component: goods,
    meta: {title: '商品管理'}
  },{
    path: '/staff',
    name: 'staff',
    component: staff,
    meta: {title: '员工管理'}
  }]
}];

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes
});

export default router;
